package com.hp.service;

import com.hp.dao.AdminMapper;
import com.hp.pojo.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class LoginService {

    @Autowired
    private AdminMapper adminMapper;
    public Map<String, Object> loginConfirm(int userId,String passWord) {
        Map<String,Object> map=new HashMap<>();
        Admin admin=new Admin();
        admin.setAdminId(userId);
        admin.setAdminPassword(passWord);
        Admin admin1 = adminMapper.loginConfirm(admin);
        if (admin1!=null){
            map.put("msg","登陆成功！");
            map.put("state",1);
            map.put("Admin",admin1);
        }
        else {
            map.put("msg","账号或密码错误!");
            map.put("state",-1);
        }
        return map;
    }

    public Map<String, Object> getAdminNameById(int adminId) {
        Map<String,Object> map=new HashMap<>();
        map.put("admin",adminMapper.getAdminNameById(adminId));
        return map;
    }

    public Map<String, Object> ModifyPassWord(int adminId, String newPassword) {
        Map<String,Object> map=new HashMap<>();
        Admin admin=adminMapper.getAdminNameById(adminId);
        admin.setAdminPassword(newPassword);
        int n=adminMapper.modifyPassword(admin);
        if (n==1){
            map.put("msg","修改成功！");
        }
        else {
            map.put("msg","修改失败！");
        }
        return map;
    }
}
